<?php echo $this->Form->input('reservation_choice', array(
	'id'		=> 'ReservationFormSelector',
	'empty'		=> false,
	'label'		=> 'Wybierz typ rezerwacji',
	'options'	=> array(
		'NormalReservationForm'			=> 'Normalna',
		'CyclicReservationForm'			=> 'Cykliczna',
	)
));
?> 

<div id="vspace"></div>
<div id="NormalReservationForm" style="display:normal">
	<?php echo $this->Form->create('NormalReservation', array('controller'=>'NormalReservations', 'action'=>'add')); ?>
		<fieldset>
			<legend>Normalna:</legend>
			<?php echo $this->Form->input('court_id', array('empty'=>true,'options' => $courts, 'label'=>'Kort')); ?>
			<?php echo $this->Form->label('Data rezerwacji'); ?>
			<p><input class="datepicker" id="NormalDatePicker" type="text" style="width:256px"></p>
			<?php echo $this->Form->input('start_time', array('label' => 'Godzina rezerwacji', 'empty'=>true, 'options' => array()));?>
			<?php echo $this->Form->end('Dodaj'); ?>
		</fieldset>
</div>
<div id="CyclicReservationForm" style="display:none">
	<?php echo $this->Form->create('CyclicReservation', array('controller'=>'CyclicReservations', 'action'=>'add')); ?>
		<fieldset>
			<legend>Cykliczna:</legend>
			<?php echo $this->Form->input('court_id', array('empty'=>true,'options' => $courts, 'label'=>'Kort')); ?>
			<?php echo $this->Form->label('Data pierwszej rezerwacji'); ?>
			<p><input class="datepicker" id="CyclicStartDatePicker" type="text" style="width:256px"></p>
			<?php echo $this->Form->input('start_time', array('label' => 'Godzina rezerwacji', 'empty'=>true, 'options' => array()));?>
			<?php echo $this->Form->label('Data końca rezerwacji'); ?>
			<p><input class="datepicker" id="CyclicEndDatePicker" type="text" style="width:256px"></p>
			<?php echo $this->Form->hidden('end_time'); ?>
			<?php echo $this->Form->input('how_often', array('label' => 'Co ile dni')); ?>
			<?php echo $this->Form->end('Dodaj'); ?>
		</fieldset>
</div>

<script>
	$(document).ready(function() {
		$('#ReservationFormSelector').change(function() {
			$('#ReservationFormSelector option:not(:selected)').each(function() {
				$('#'+$(this).val()).hide(1000);
			});
			$('#ReservationFormSelector option:selected').each(function() {
				$('#'+$(this).val()).show(1000);
			});
		});
		
	});
		$(function() {
		$( ".datepicker" ).datepicker({
			minDate: 0
		});
	});
	jQuery(function($) {
	$.datepicker.regional['pl'] = {
		closeText: 'Zamknij',
		prevText: '&#x3c;Poprzedni',
		nextText: 'Następny&#x3e;',
		currentText: 'Dziś',
		monthNames: ['Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec',
		'Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'],
		monthNamesShort: ['Sty','Lu','Mar','Kw','Maj','Cze',
		'Lip','Sie','Wrz','Pa','Lis','Gru'],
		dayNames: ['Niedziela','Poniedziałek','Wtorek',' Środa','Czwartek','Piątek','Sobota'],
		dayNamesShort: ['Nie','Pn','Wt','Śr','Czw','Pt','So'],
		dayNamesMin: ['N','Pn','Wt','Śr','Cz','Pt','So'],
		weekHeader: 'Tydz',
		dateFormat: 'yy-mm-dd',
		firstDay: 1,
		isRTL: false,
		showMonthAfterYear: false,
		yearSuffix: ''};
	$.datepicker.setDefaults($.datepicker.regional['pl']);
});
	// Rezerwacje normalne
	$('#NormalReservationCourtId').change(function() {
		var court_id = "";
		court_id = $('#NormalReservationCourtId option:selected').val();
		
		$.post('/korty_tenisowe/reservations/jsSetAvailableHours', {court_id: court_id}, function(response) {
			
			var obj = jQuery.parseJSON(response);
			var options = $("#NormalReservationStartTime");
			options.find('option').remove().end();
			
			$('#NormalDatePicker').val("");
			$.each(obj, function(key, value) {
				options.append($("<option />").val(value).text(key));
			});
		});
	});
	$('#NormalDatePicker').change(function() {
		court_id = $('#NormalReservationCourtId option:selected').val();
		
		$.post('/korty_tenisowe/reservations/jsSetAvailableHours', {dateText:$(this).val(), court_id: court_id, isNormal: true}, function(response) {
			
			var obj = jQuery.parseJSON(response);
			var options = $("#NormalReservationStartTime");
			options.find('option').remove().end();
			$.each(obj, function(key, value) {
				options.append($("<option />").val(value).text(key));
			});
		});
	});
	
	// Rezerwacje cykliczne
	$('#CyclicReservationCourtId').change(function() {
		var court_id = "";
		court_id = $('#CyclicReservationCourtId option:selected').val();
		
		$.post('/korty_tenisowe/reservations/jsSetAvailableHours', {court_id: court_id}, function(response) {
			
			var obj = jQuery.parseJSON(response);
			var options = $("#CyclicReservationStartTime");
			options.find('option').remove().end();
			
			$('#CyclicStartDatePicker').val("");
			$('#CyclicEndDatePicker').val("");
			$.each(obj, function(key, value) {
				options.append($("<option />").val(value).text(key));
			});
		});
	});
	$('#CyclicStartDatePicker').change(function() {
		court_id = $('#CyclicReservationCourtId option:selected').val();
		
		$.post('/korty_tenisowe/reservations/jsSetAvailableHours', {dateText:$(this).val(), court_id: court_id}, function(response) {
			
			var obj = jQuery.parseJSON(response);
			var options = $("#CyclicReservationStartTime");
			options.find('option').remove().end();
			$.each(obj, function(key, value) {
				options.append($("<option />").val(value).text(key));
			});
		});
	});
	$('#CyclicEndDatePicker').change(function() {
		$("#CyclicReservationEndTime").val($('#CyclicEndDatePicker').val());
	});
</script>
